package com.fishery.monitor.controller;


import com.fishery.entity.Result;
import com.fishery.entity.StatusCode;
import com.fishery.monitor.pojo.MonitorBase;
import com.fishery.monitor.service.BaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 控制器层
 * @author Administrator
 *
 */
@Api(tags = "基地接口")
@RestController
@CrossOrigin
@RequestMapping("/base")
public class BaseController {

	@Autowired
	private BaseService baseService;
	
	
	/**
	 * 查询全部数据
	 * @return
	 */
	@ApiOperation("查询全部数据")
	@RequestMapping(method= RequestMethod.GET)
	public Result findAll(){
		return new Result(true, StatusCode.OK,"查询成功",baseService.findAll());
	}
	
	/**
	 * 根据ID查询
	 * @param id ID
	 * @return
	 */
	@ApiOperation("根据ID查询")
	@RequestMapping(value="/{id}",method= RequestMethod.GET)
	public Result findById(@PathVariable String id){
		return new Result(true,StatusCode.OK,"查询成功",baseService.findById(id));
	}


	/**
	 * 分页+多条件查询
	 * @param searchMap 查询条件封装
	 * @param page 页码
	 * @param size 页大小
	 * @return 分页结果
	 */
	@ApiOperation("分页+多条件查询")
	@RequestMapping(value="/search/{page}/{size}",method= RequestMethod.POST)
	public Result findSearch(@RequestBody @ApiParam(name = "查询条件，属性：值 形式",required = true,value = "searchMap") Map searchMap , @PathVariable int page, @PathVariable int size){
		return  new Result(true,StatusCode.OK,"查询成功",  baseService.findSearch(searchMap, page, size));
	}

	/**
     * 根据条件查询
     * @param searchMap
     * @return
     */
	@ApiOperation("根据条件查询")
	@RequestMapping(value="/search",method = RequestMethod.POST)
	public Result findSearch( @RequestBody @ApiParam(name = "查询条件，属性：值 形式",required = true,value = "searchMap") Map searchMap){
        return new Result(true,StatusCode.OK,"查询成功",baseService.findSearch(searchMap));
    }
	
	/**
	 * 增加
	 * @param monitorBase
	 */
	@ApiOperation("增加")
	@RequestMapping(method= RequestMethod.POST)
	public Result add(@RequestBody @ApiParam(name = "基地对象",required = true,value = "monitorBase") MonitorBase monitorBase  ){
		baseService.add(monitorBase);
		return Result.success("增加成功");
	}

	/**
	 * 修改
	 * @param monitorBase
	 */
	@ApiOperation("修改")
	@RequestMapping(value="/{id}",method= RequestMethod.PUT)
	public Result update(@RequestBody @ApiParam(name = "基地对象",required = true,value = "monitorBase") MonitorBase monitorBase, @PathVariable String id ){
		monitorBase.setId(id);
		baseService.update(monitorBase);
		return Result.success("修改成功");
	}
	
	/**
	 * 删除
	 * @param id
	 */
	@ApiOperation("删除")
	@RequestMapping(value="/{id}",method= RequestMethod.DELETE)
	public Result delete(@PathVariable String id ){
		baseService.deleteById(id);
		return Result.success("删除成功");
	}
	
}
